package com.easyExcel;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

public class StateConverter implements Converter<Integer> {

    public static final String NORMAL_STR = "正常";
    public static final String DISABLE_STR = "禁用";

    public static final Integer NORMAL_NUM = 1;
    public static final Integer DISABLE_NUM = 2;

    @Override
    public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return cellData.getStringValue().equals(NORMAL_STR)?1:0;
    }

    @Override
    public WriteCellData<?> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return new WriteCellData<>(value.equals(1)?"正常":"禁用");
    }

}
